# @Time : 2024-11-06 17:46
# @Author : Fioman 
# @Phone : 13149920693
"""
线程池按照提交的顺序获取结果:
迭代futures列表,然后逐个调用它的result(),这个函数会阻塞.
按照顺序调用result(),然后返回结果,将结果放到一个结果列表中,列表中就是有顺序的
"""
import threading
import time
from concurrent.futures import ThreadPoolExecutor


def show_task():
    print(f"{threading.current_thread().name} 正在运行")
    time.sleep(2)
    print(f"{threading.current_thread().name} 运行结束")
    return f"{threading.current_thread().name} 返回"


if __name__ == '__main__':
    with ThreadPoolExecutor(max_workers=5, thread_name_prefix="task_") as executor:
        futures = [executor.submit(show_task) for _ in range(10)]
        results = []
        for future in futures:
            results.append(future.result())

    print(f"所有的返回结果: {results}")
